<!---选择人员-->
<template>
  <div>
    <el-input v-model="temp.Name" prop="Name" name="Name" :disabled="disabled" @focus="showSelectBillDialog()" />
    <singlechoiceperson ref="refSinglePerson" :echo-list="checkedUsers" @allSelect="allSelect" />
  </div>
</template>
<script>
import singlechoiceperson from '@/views/components/permissions/singlechoiceperson'
export default {
  components: {
    singlechoiceperson
  },
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      dialogVisible: false,
      checkedUsers: [], // 打开弹窗选择的用户
      temp: this.data || { Name: '' }
    }
  },
  watch: {
    data: {
      deep: true,
      handler() {
        if (this.data.Id) {
          this.temp = this.data
        }
      }
    }
  },
  methods: {
    showSelectBillDialog() {
      this.dialogVisible = true
      if (this.temp.Id) {
        this.checkedUsers[0] = this.temp
      }
      this.$refs.refSinglePerson.singlepersonref()
    },
    // 选择人员时回调方法
    allSelect(taglist) {
      if (taglist != null && taglist.length > 0) {
        this.temp = taglist[0]
      }
      this.$emit('update:data', this.temp)
    }
  }
}
</script>
